##################################################################################################################
# Code for running running code files for replicating main results and supplemental results in 
# "(When) Are Lobbying Expenditures a Good Proxy for Lobbying Activity?" via "source()" command
##################################################################################################################

##################################################################################################################
# To run, please set the working directory to match the location of the folder containing all replication files.
##################################################################################################################
#setwd("Replication_PSRM_ST24")

#Information about R Version used
as.data.frame(R.Version())
#   platform                arch       os           system status major minor year month day svn.rev language               version.string  nickname
# 1 x86_64-apple-darwin20 x86_64 darwin20 x86_64, darwin20            4   4.0 2024    04  24   86474        R R version 4.4.0 (2024-04-24) Puppy Cup

#The following packages (package versions) are used in running the below code files (code checks whether package is
# already installed and will install if necessary, though not necessarily the below versions)

# "dplyr" ; package version: 1.1.4
# "DescTools" ; package version: 0.99.54
# "knitr" ; package version: 1.47
# "kableExtra" ; package version: 1.4.0
# "weights" ; package version: 1.0.4
# "Hmisc" ; package version: 5.1.3
# "Metrics" ; package version: 0.1.4
# "stargazer" ; package version: 5.2.3


#Clear environment
rm(list=ls());gc();gc();gc();gc()

###Main Results
source("Code_Files/Main_Results.R",echo=T,max.deparse.length=Inf)

###Appendix Results

#Appendix Section A1.1
source("Code_Files/Appendix_A1_1.R",echo=T,max.deparse.length=Inf)

#Appendix Section A1.2
source("Code_Files/Appendix_A1_2.R",echo=T,max.deparse.length=Inf) #N.B. this requires "lobby_lda.zip" to be unzipped which takes up approx. 725 MB

#Appendix Section A1.3
source("Code_Files/Appendix_A1_3.R",echo=T,max.deparse.length=Inf)

#Appendix Section A4
source("Code_Files/Appendix_A4.R",echo=T,max.deparse.length=Inf)

#Appendix Section A5.1
source("Code_Files/Appendix_A5_1.R",echo=T,max.deparse.length=Inf)

#Appendix Sections A5.2, A5.3, and A5.4
source("Code_Files/Appendix_A5_2-A5_4.R",echo=T,max.deparse.length=Inf)

#Appendix Sections A5.5, A5.6, and A5.7
source("Code_Files/Appendix_A5_5-A5_7.R",echo=T,max.deparse.length=Inf)

#Appendix Section A5.8
source("Code_Files/Appendix_A5_8.R",echo=T,max.deparse.length=Inf) #N.B. this requires "lobby_lda.zip" to be unzipped which takes up approx. 725 MB

#Appendix Section A5.9
source("Code_Files/Appendix_A5_9.R",echo=T,max.deparse.length=Inf)

#Appendix Section A6
source("Code_Files/Appendix_A6.R",echo=T,max.deparse.length=Inf)

#Appendix Section A7
source("Code_Files/Appendix_A7.R",echo=T,max.deparse.length=Inf) #N.B. due to the simulation analysis, running this code can take over an hour

